package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.Map;

@Mapper
public interface UserMapper {

    /**
     * 根据动态条件统计用户数量
     *
     * @param map
     * @return
     */
    Integer countByMap(Map<String, Object> map);

    /**
     * 根据openid来查找用户
     * @param openid
     * @return
     */
    @Select("select * from sky_take_out.user where openid = #{openid}")
    User getUserByOpenId(String openid);

    /**
     * 插入新用户 用户端功能
     * @param user
     */
    void insertUser(User user);

    /**
     * 根据用户的id来查询对应的用户信息
     * @param userId
     * @return
     */
    @Select("select * from sky_take_out.user where id = #{userId}")
    User getById(Long userId);

    /**
     * 根据时间区间 统计相应的用户总量
     * select count(id) from user where create_time < ?
     * @param endTime
     * @return
     */
    Integer countUserNumberByTime(LocalDateTime endTime);

    /**
     * 根据时间区间 统计相应区间内用户的数量数据
     * 对于新增 select count(id) from user where create_time > ? and create_time < ?
     * @param beginTime
     * @param endTime
     * @return
     */
    Integer countUserNewByTime(LocalDateTime beginTime, LocalDateTime endTime);
}
